﻿using FFMpegSharp;
using FFMpegSharp.Enums;
using FFMpegSharp.FFMPEG;
using FFMpegSharp.FFMPEG.Enums;
using System;
using System.IO;
using System.Windows.Forms;

namespace winform_ffmpeg_video_convert_audio {
  internal class FFmpegUtils {

    /// <summary>
    /// 提取音频
    /// </summary>
    /// <param name="inputVideoFile"></param>
    /// <param name="outputAudioFile"></param>
    /// <param name="textLog"></param>
    internal static void ExtractAudio(string inputVideoFile, string outputAudioFile, TextBox textLog) {
      LogUtils.WriteLine(string.Format("start convert,dest audio:{0}", outputAudioFile), textLog);

      var encoder = new FFMpeg();
      encoder.OnProgress += (percentage) => LogUtils.WriteLine(String.Format("Progress {0}%", percentage), textLog);
      encoder.ExtractAudio(VideoInfo.FromPath(inputVideoFile), new FileInfo(outputAudioFile));
      LogUtils.WriteLine("finished", textLog);
      
    }
  }
}